﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Sample
{
    public class Stack
    {
        private List<ICounter> counters;

        public Stack(Int32 maxSize, IEnumerable<ICounter> counters)
        {
            if (maxSize < 0) throw new ArgumentException("maxSize must be at least 0");

            this.TotalSpace = maxSize;
            this.counters = new List<ICounter>(counters);

            if (this.counters.Sum(c => c.StackingSpace) > this.TotalSpace) throw new InvalidOperationException("Too many counters");
        }

        public Int32 CalculateAttack()
        {
            var a = (from c in this.counters select c.Attack).Sum();
            return a;
        }

        public Int32 CalculateDefense()
        {
            var d = (from c in this.counters select c.Defense).Sum();
            return d;
        }

        public Int32 TotalSpace
        {
            get; private set;
        }
    }
}
